﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ArticleManager.DataClasses
{
    public class TableData
    {
        string keyQuery;
        string createQuery;
        bool Exists;
        bool KeyExists;
        string strName;

        ColumnDataCollection columnData;

        public TableData()
        {
            KeyExists = false;
            Exists = false;
            createQuery = string.Empty;
            strName = string.Empty;
            keyQuery = string.Empty;
            columnData = new ColumnDataCollection();
            columnData.Clear();
        }

        public override string ToString()
        {
            return strName;
        }
        public string Name
        {
            get { return this.strName; }
            set { this.strName = value; }
        }

        public string KeyQuery
        {
            get { return this.keyQuery; }
            set { this.keyQuery = value; }
        }

        public string Query
        {
            get 
            { 
                return this.createQuery + " " + strName; 
            }
            set { this.createQuery = value; }
        }
        public bool Exist
        {
            get { return this.Exists; }
            set { this.Exists = value; }
        }

        public bool KeyExist
        {
            get { return this.KeyExists; }
            set { this.KeyExists = value; }
        }

        public ColumnDataCollection Columns 
        {
            get { return this.columnData; }
            set { this.columnData = value; }
        }
    }

    public class TableDataCollection : System.Collections.CollectionBase
    {
        public int Add(TableData value)
        {
            return base.List.Add(value as object);
        }

        public void Remove(TableData value)
        {
            base.List.Remove(value as object);
        }

        public void Insert(int index, TableData value)
        {
            base.List.Insert(index, value as object);
        }

        public bool Contains(TableData value)
        {
            return base.List.Contains(value as object);
        }

        public TableData this[int index]
        {
            get { return base.List[index] as TableData; }
        }

        public int this[string name]
        {
            get 
            {
                for (int i = 0; i < base.List.Count; i++)
                {
                    if (base.List[i].ToString().CompareTo(name) == 0)
                        return i;
                }
                return -1;                
            }
        }

    }
}
